import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/call_remind/call_const.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'call_remind_logic.dart';

class CallRemindPage extends StatelessWidget {
  CallRemindPage({super.key});

  final logic = Get.put(CallRemindLogic());
  final state = Get.find<CallRemindLogic>().state;

  @override
  Widget build(BuildContext context) {
    state.callRingRing = logic.read(CallConst.keyCallRingRing, defaultValue: false);
    state.callRingVibrate = logic.read(CallConst.keyCallRingVibrate, defaultValue: false);
    state.callRingRingVibrate = logic.read(CallConst.keyCallRingRingVibrate, defaultValue: false);
    state.callRingMute = logic.read(CallConst.keyCallRingMute, defaultValue: false);

    return Scaffold(
      backgroundColor: ColorConst.mainBgColor,
      appBar: AppBar(
        backgroundColor: ColorConst.mainBgColor,
        title: Text(LocaleKeys.settings_call_remind.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
        // leading: IconButton(
        //   padding: EdgeInsets.only(left: 40.w,),
        //   icon: Image.asset("assets/images/space/icon_appbar_arrow_back.png"),
        //   onPressed: () {Get.back();},
        // ),
        // leadingWidth: 25,
      ),
      body: Padding(
        padding: EdgeInsets.only(left: 40.w, top: 80.h, right: 40.w),
        child: ListView(
          children: [
            Container(height: 99.h,),
            Image(
              width: 746.w,
              height: 290.h,
              image: const AssetImage("assets/images/device/call_remind_logo.png"),),
            Container(
                margin: EdgeInsets.only(top: 100.h),
                padding: EdgeInsets.fromLTRB(60.w, 20.h, 36.w, 60.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                        GetBuilder<CallRemindLogic>(
                          id: CallConst.keyCallRemindEnable,
                          builder: (value){
                            return Text(
                              state.callRemindEnable ? LocaleKeys.call_remind_on.ts : LocaleKeys.call_remind_off.ts,
                              style: TextStyle(fontSize: 42.sp, color: ColorConst.primaryFontColor),);},),
                          Transform.scale(
                              scale: 0.7,
                              child: GetBuilder<CallRemindLogic>(
                                id: CallConst.keyCallRemindEnable,
                                builder: (value){
                                  return CupertinoSwitch(
                                      value: state.callRemindEnable,
                                      activeColor: ColorConst.accentColor,
                                      onChanged: (value) {
                                        logic.setCallRemindEnable(value);
                                      });
                                },)),
                        ]),
                    Text(LocaleKeys.call_remind_tips.ts, style: TextStyle(fontSize: 36.sp, color: Color(0xFF898C8F)))
                  ],)),
            SizedBox(height: 39.h),
            // GetBuilder<CallRemindLogic>(
            //     id: CallConst.keyCallRemindEnable,
            //     builder: (_){
            //       return Opacity(opacity: state.callRemindEnable?1:0,
            //         child: _buildHangup());}),
            // SizedBox(height: 40.h),
            /// sdk不支持，暂时屏蔽
            // GetBuilder<CallRemindLogic>(
            //     id: CallConst.keyCallRemindEnable,
            //     builder: (_){
            //       return Opacity(opacity: state.callRemindEnable?1:0,
            //           child: _buildRing());}),
          ],),),);
  }

  Widget _buildHangup() {
    Widget widget = Container(
        padding: EdgeInsets.fromLTRB(60.w, 20.h, 36.w, 60.h),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(LocaleKeys.call_ring_off.ts, style: TextStyle(fontSize: 42.sp, color: ColorConst.primaryFontColor),),
                  Transform.scale(
                      scale: 0.7,
                      child: GetBuilder<CallRemindLogic>(
                        id: 'call_remind_hangup',
                        builder: (value){
                          return CupertinoSwitch(
                              value: state.callRemindHangup,
                              activeColor: ColorConst.accentColor,
                              onChanged: (value) {
                                logic.setCallRemindHangup(value);
                              });
                        },)),
                ]),
            Container(
              width: 570.w,
              child: Text(LocaleKeys.call_ring_off_tips.ts, style: TextStyle(fontSize: 36.sp, color: Color(0xFF898C8F))),
            )
          ],));
    return widget;
  }

  Widget _buildRing() {
    Widget widget = GestureDetector(
      onTap: (){Get.toNamed('/device/settings/call_rainging');},
      child: Container(
        padding: EdgeInsets.fromLTRB(60.w, 60.h, 36.w, 60.h),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(
          children: [
            Text(LocaleKeys.call_ringing_mode.ts, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),),
            Expanded(child: Container()),
            GetBuilder<CallRemindLogic>(
                id: 'call_ring_text',
                builder: (_){
                  return Text(logic.getCallRing(), style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor));
                }),
            SizedBox(width: 78.h),
            const Icon(Icons.arrow_forward_ios, size: 16,),
          ],),),);
    return widget;
  }
}
